package com.unknow.first.dapp.admin.account.controller;

import com.unknow.first.dapp.admin.account.mapper.AddressCoinConfig;
import com.unknow.first.dapp.admin.account.service.AddressCoinConfigService;
import com.unknow.first.dapp.admin.account.vo.ChargeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.math.BigDecimal;
import java.util.List;
import org.cloud.utils.CollectionUtil;
import org.cloud.vo.CommonApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.web3j.abi.datatypes.Address;

@RestController
@RequestMapping("/coin/config")
@Api(value = "APP:币种信息", tags = "APP:币种信息")
public class AddressCoinConfigController {

    @Autowired
    private AddressCoinConfigService addressCoinConfigService;

    @RequestMapping(method = RequestMethod.GET, value = "/coinList")
    @ApiOperation("查询币种列表")
    public CommonApiResult<List<AddressCoinConfig>> coinList() {
        return CommonApiResult.createSuccessResult(addressCoinConfigService.getList(true));
    }


    @RequestMapping(method = RequestMethod.GET, value = "/estimatedCharge")
    @ApiOperation("预估手续费")
    public CommonApiResult<ChargeVO> estimatedCharge(@RequestParam("coinId") Integer coinId,
        @RequestParam(value = "middlePath", required = false) List<Address> middlePath, @RequestParam("amount") BigDecimal amount) throws Exception {
        if (CollectionUtil.single().isNotEmpty(middlePath)) {
            return CommonApiResult.createSuccessResult(addressCoinConfigService.estimatedCharge(coinId, middlePath, amount));
        } else {
            return CommonApiResult.createSuccessResult(addressCoinConfigService.estimatedCharge(coinId, amount));
        }
    }
}
